//
//  HomeViewController.m
//  pocketNews
//
//  Created by DS on 2018/10/26.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "HomeViewController.h"

#import "LXScollTitleView.h"
#import "LXScrollContentView.h"
#import "HomeSonViewController.h"

#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]



#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

@interface HomeViewController ()

@property (nonatomic, strong) LXScollTitleView *titleView;

@property (nonatomic, strong) LXScrollContentView *contentView;

Strong UIView * BlueView;

Strong NSArray * titleArr;

Strong NSArray * titleInfoArr;

Strong UILabel * titleLabel;




@end

@implementation HomeViewController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    
      //[self.navigationController setNavigationBarHidden:YES animated:NO];
 
}

- (void)viewDidDisappear:(BOOL)animated{
    
    [super viewDidDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
  
    
    [self.view addSubview:self.BlueView];
    
    [self.view addSubview:self.titleLabel];
   
    
    [self setupUI];
    [self reloadData];
    


}

- (UIView *)BlueView{
    
    if (!_BlueView ) {
        
        _BlueView = [[UIView alloc] init];
        _BlueView.frame = CGRectMake(0, 0, SCREEN_WIDTH, UNIT_HEIGHT(135));
        int r = arc4random() % 255;
        int g = arc4random() % 255;
        int b = arc4random() % 255;
        CGFloat rr = r / 255.0;
        CGFloat rg = g / 255.0;
        CGFloat rb = b / 255.0;
        _BlueView.backgroundColor = [[UIColor alloc]initWithRed:rr green:rg blue:rb alpha:1];
        
    }
    
    return _BlueView;
    
}

- (UILabel *)titleLabel{
    
    if (!_titleLabel) {
        
        self.titleLabel = [UILabel addLabelWithFrame:CGRectMake(UNIT_WIDTH(10), UNIT_HEIGHT(50), SCREEN_WIDTH - UNIT_WIDTH(10), UNIT_HEIGHT(30)) AndText:@"口袋新闻" AndFont:20 AndAlpha:1 AndColor:getColor(whiteColor)];
    
       
    }
    
    return _titleLabel;
    
}




- (void)setupUI{
    self.titleView = [[LXScollTitleView alloc] initWithFrame:CGRectZero];
    __weak typeof(self) weakSelf = self;
    self.titleView.selectedBlock = ^(NSInteger index){
        __weak typeof(self) strongSelf = weakSelf;
        strongSelf.contentView.currentIndex = index;
        
        int r = arc4random() % 255;
        int g = arc4random() % 255;
        int b = arc4random() % 255;
        CGFloat rr = r / 255.0;
        CGFloat rg = g / 255.0;
        CGFloat rb = b / 255.0;
        strongSelf.BlueView.backgroundColor = [[UIColor alloc]initWithRed:rr green:rg blue:rb alpha:1];
    };
    self.titleView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    self.titleView.titleWidth = 60.f;
    self.titleView.normalColor = getColor(whiteColor);
    self.titleView.selectedColor = getColor(whiteColor);
    self.titleView.backgroundColor = [UIColor clearColor];
    self.titleView.titleFont = DEF_FontSize_16;
    //self.titleView.backgroundColor = getColor(@"1E7CD2");
    [self.view addSubview:self.titleView];
    
    self.contentView = [[LXScrollContentView alloc] initWithFrame:CGRectZero];
    self.contentView.scrollBlock = ^(NSInteger index){
        __weak typeof(self) strongSelf = weakSelf;
       
        strongSelf.titleView.selectedIndex = index;
      
         strongSelf.navigationController.navigationBar.hidden = YES;
      
        int r = arc4random() % 255;
        int g = arc4random() % 255;
        int b = arc4random() % 255;
        CGFloat rr = r / 255.0;
        CGFloat rg = g / 255.0;
        CGFloat rb = b / 255.0;
       strongSelf.BlueView.backgroundColor = [[UIColor alloc]initWithRed:rr green:rg blue:rb alpha:1];
     
        
    };
    [self.view addSubview:self.contentView];
    
    
}




- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.titleView.frame = CGRectMake(0, UNIT_HEIGHT(100), self.view.frame.size.width, 35);
    self.contentView.frame = CGRectMake(0,  35 + UNIT_HEIGHT(100), self.view.frame.size.width, SCREEN_HEIGHT - UNIT_HEIGHT(100) - 35 - height49 );
}

- (void)reloadData{
    
    self.titleArr = @[@"头条",@"国内",@"体育",@"军事",@"科技",@"时尚"];
    self.titleInfoArr = @[@"top",@"guonei",@"tiyu",@"junshi",@"keji",@"shishang"];
    
    NSArray *titles  = self.titleArr;
    [self.titleView reloadViewWithTitles:titles];
    
    NSMutableArray *vcs = [[NSMutableArray alloc] init];
    for (int i = 0;i<self.titleArr.count;i++) {
        HomeSonViewController *vc = [[HomeSonViewController alloc] init];
        
        vc.type = self.titleInfoArr[i];
        
        [vcs addObject:vc];
    }
    [self.contentView reloadViewWithChildVcs:vcs parentVC:self];
    
    
    
    
}


@end
